<template>
  <div class="bg">
    <div class="login">
      <div class="titl">
        <span>新海联OA系统</span>
      </div>
      <div class="userName">
        <span class="icon"></span>
        <input type="text" placeholder="请输入用户名" v-model="username">
      </div>
      <div class="pw">
        <span class="icon"></span>
        <input type="password" placeholder="请输入密码" v-model="password">
      </div>
      <div class="hintBox">
        <span ref="hint"></span>
      </div>
      <div class="loginBtn">
        <input type="button" value="登录" @click="login">
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        username: '',
        password: ''
      };
    },
    methods: {
      login() {
        if (this.username.trim().length === 0 || this.password.trim().length === 0) {
          this.$refs.hint.innerText = '用户名或密码不能为空';
          return;
        }
        let data = {
          username: this.username,
          password: this.password
        }

        this.apiPost('Index/login', data).then(res => {
          if (!res.error) {
            _g.toastMsg('success', '登录成功')
            router.push('/')
          } else {
            this.$refs.hint.innerText = res.msg;
          }
        })
      }
    },
    // mounted() {
    //   window.addEventListener('keyup', (e) => {
    //     if (e.keyCode === 13) {
    //       this.login()
    //     }
    //   })
    // },
  }
</script>
<style lang="css" scoped>
  .bg {
    background: url('../img/bg.png') no-repeat;
    background-size: 100% 100%;
    width: 100%;
    height: 100%;
    position: relative;
  }


  .bg .login {
    width: 450px;
    height: 350px;
    background-color: #fff;
    border-radius: 10px;
    position: absolute;
    right: 150px;
    top: 30%;
    text-align: center;
  }

  .bg .login .titl {
    font-size: 30px;
    color: #333;
    padding-top: 40px;
  }

  .hintBox {
    font-size: 14px;
    color: red;
    height: 30px;
    line-height: 30px;
  }

  .bg .login input {
    width: 300px;
    height: 30px;
    font-size: 16px;
    color: #333;
    padding: 0 30px;
    box-sizing: border-box;
    outline: none;
    border: 0;
    border-bottom: 1px solid #e5e5e5;

    text-align: center;
  }

  .userName {
    margin-top: 50px;
    position: relative;
  }

  .pw {
    margin-top: 30px;
    position: relative;
  }

  .icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    position: absolute;
    top: 5px;
    left: 75px;
  }

  .userName .icon {
    background: url('../img/icon-head.png') no-repeat;
  }

  .pw .icon {
    background: url('../img/icon-pw.png') no-repeat;
  }

  .loginBtn {
    margin-top: 30px;
  }

  .login .loginBtn input {
    height: 40px;
    border-radius: 25px;
    background-color: #3f9ce2;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
  }
</style>
